package com.dyzx.hbb.modules.sys.controller;

import com.dyzx.hbb.common.base.Result;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.common.controller.BaseController;
import com.dyzx.hbb.modules.sys.entity.SysWorkFlow;
import com.dyzx.hbb.modules.sys.query.WorkFlowQuery;
import com.dyzx.hbb.modules.sys.service.SysWorkFlowService;
import com.dyzx.hbb.modules.sys.vo.WorkFlowUVO;
import com.dyzx.hbb.modules.sys.vo.WorkFlowVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/sys/work/flow")
@RestController
@Tag(name = "13.工单流程管理", description = "工单流程相关接口")
public class WorkFlowController extends BaseController<SysWorkFlowService, SysWorkFlow, WorkFlowQuery, WorkFlowVO, WorkFlowUVO> {
    @Autowired
    private SysWorkFlowService service;

    @Override
    protected SysWorkFlowService getBaseService() {
        return service;
    }

    @Override
    protected MyLambdaQueryWrapper<SysWorkFlow> queryWrapper(WorkFlowQuery query) {

        MyLambdaQueryWrapper<SysWorkFlow> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.orderByDesc(SysWorkFlow::getId);
        queryWrapper.select(SysWorkFlow::getId, SysWorkFlow::getName, SysWorkFlow::getDescription, SysWorkFlow::getServiceHours,SysWorkFlow::getServiceAmt, SysWorkFlow::getCommission, SysWorkFlow::getType);

        return queryWrapper;
    }

    @Override
    protected MyLambdaQueryWrapper<SysWorkFlow> queryInfoWrapper() {
        MyLambdaQueryWrapper<SysWorkFlow> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.orderByDesc(SysWorkFlow::getId);
        queryWrapper.select(SysWorkFlow::getId, SysWorkFlow::getName,
                SysWorkFlow::getDescription, SysWorkFlow::getServiceHours,SysWorkFlow::getServiceAmt,
                SysWorkFlow::getCommission, SysWorkFlow::getType);

        return queryWrapper;
    }

    @GetMapping("/mini_list")
    public Result<List<Map<String, Object>>> miniList() {
        MyLambdaQueryWrapper<SysWorkFlow> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(SysWorkFlow::getId).as("value");
        queryWrapper.select(SysWorkFlow::getName).as("label");
        queryWrapper.orderByDesc(SysWorkFlow::getId);
        List<Map<String, Object>> maps = service.listMaps(queryWrapper);
        if (maps.isEmpty()) {
            return Result.error(404, "暂无数据");
        }
        return Result.ok(maps);
    }
}
